#pragma once
#ifndef FUNCTIONS_H
#define FUNCTIONS_H

#include <iostream>
#include "json/json.h"  // 使用jsoncpp库解析JSON数据
#include "curl/curl.h"
#include <string>
#include <cstring>
#include <openssl/md5.h>
#include <algorithm>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <unistd.h>

extern std::string SERVER_IP;
extern std::string GUANLIAN_IP;
extern std::string RENZHENG_IP;
extern std::string HOST_NAME;

class Functions {
public:
    static Json::Value stringToJson(const std::string& str);        
    static std::string jsonToString(const Json::Value& jsonValue);
    static void sln_bin2str(
    char *str,
    unsigned char *ptr,
    int len);
    static std::string unsignedCharArrayToString(const unsigned char *array, size_t length);
    static size_t my_write_callback(char* ptr, size_t size, size_t nmemb, std::string* stream);
    static Json::Value send_get_request(const std::string& url);
    static Json::Value send_post_request(const std::string& url, const std::string& json_data);
    static Json::Value processCidAndGetRid(const std::string& cid);
    static std::string processRidAndGetCid(const std::string& rid);
    static std::string processCidAndGetMid(const std::string& cid);
    static std::string processRidAndGetMid(const std::string& rid);
    static std::string calculateMD5Hash(const std::string& jsonStr);
    static std::string extractJsonData(const std::string& requestData); //分割出post请求中的json字符串
    static void URLEncode(std::string& str);
    static void ipv6_to_str_unexpanded(char *str, const struct in6_addr *addr);
    static void send_router_addr();
    static int  getCache(const std::string& service_id);
    static int  getCheck(const std::string& service_id);
};

#endif

